/************************************************************************/
/*    Author: Scott Bevin                                               */
/************************************************************************/

#include "GameScreen.h"

namespace XF
{
	GameScreen::GameScreen(bool isPopup)
	{
		mTransitionOnTime = 0.5f;
		mTransitionOffTime = 0.5f;
		mIsPopup = isPopup;
	}

	GameScreen::~GameScreen()
	{
	}

	bool GameScreen::Initialise(GameScreenManagerComponent *screenManager)
	{
		mScreenManager = screenManager;

		mRenderer = mScreenManager->GetRenderer();
		
		TransitionOn();		
		
		mScreenLifeTime = 0.0f;

		return OnInitialise();
	}

	void GameScreen::HandleInput(double dT, Input *input)
	{
		OnHandleInput(dT, input);
	}

	void GameScreen::Update(double dT)
	{
		switch(mScreenState)
		{
		case ScreenState::SCREEN_TRANSITION_ON:
			if((mTransitionTimer += dT) >= mTransitionOnTime)
			{
				OnScreenJustWentActive();
				mScreenState = ScreenState::SCREEN_ACTIVE;
			}
			break;
		case ScreenState::SCREEN_ACTIVE:
			mScreenLifeTime += dT;
			break;
		case ScreenState::SCREEN_TRANSITION_OFF:
			if((mTransitionTimer += dT) >= mTransitionOffTime)
			{
				OnScreenJustWentInActive();
				mScreenState = ScreenState::SCREEN_NOT_ACTIVE;
			}
			break;
		}

		OnUpdate(dT);
	}

	void GameScreen::Shutdown()
	{
		OnShutDown();
	}

	void GameScreen::TransitionOn()
	{
		mScreenState = ScreenState::SCREEN_TRANSITION_ON;
		mTransitionTimer = 0.0f;
	}

	void GameScreen::TransitionOff()
	{
		mScreenState = ScreenState::SCREEN_TRANSITION_OFF;
		mTransitionTimer = 0.0f;
	}

	float GameScreen::TransitionDelta()
	{
		switch(mScreenState)
		{
		case ScreenState::SCREEN_TRANSITION_ON:
			return (mTransitionTimer / mTransitionOnTime);
		case ScreenState::SCREEN_ACTIVE:
			return 1.0f;
		case ScreenState::SCREEN_TRANSITION_OFF:
			return (1.0f - (mTransitionTimer / mTransitionOffTime));
		}

		return 0;
	}
}
